<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 3.9.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"mjava.top","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":true},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="浅水是喧哗的，深水是沉默的">
<meta name="keywords" content="Java,Linux,Spring,Jenkins,Docker,RocketMQ,Vue">
<meta property="og:type" content="website">
<meta property="og:title" content="灰色World">
<meta property="og:url" content="http://mjava.top/page/6/index.html">
<meta property="og:site_name" content="灰色World">
<meta property="og:description" content="浅水是喧哗的，深水是沉默的">
<meta property="og:locale" content="zh-CN">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="灰色World">
<meta name="twitter:description" content="浅水是喧哗的，深水是沉默的">

<link rel="canonical" href="http://mjava.top/page/6/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>灰色World</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="灰色World" type="application/atom+xml"><!-- hexo-inject:begin --><!-- hexo-inject:end -->
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>

<body itemscope itemtype="http://schema.org/WebPage">
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">灰色World</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/greycode9" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener external nofollow noreferrer" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://mjava.top/rocketmq/rocketmq-cluster-build/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="灰灰">
      <meta itemprop="description" content="浅水是喧哗的，深水是沉默的">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="灰色World">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/rocketmq/rocketmq-cluster-build/" class="post-title-link" itemprop="url">RocketMQ集群搭建</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-10-09 20:55:36" itemprop="dateCreated datePublished" datetime="2019-10-09T20:55:36+00:00">2019-10-09</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-01-27 10:07:24" itemprop="dateModified" datetime="2021-01-27T10:07:24+00:00">2021-01-27</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/RocketMq/" itemprop="url" rel="index"><span itemprop="name">RocketMq</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>  本文只讲RocketMQ集群的搭建(异步复制)，具体理论知识后续会在写新文章详细介绍;</p>
<h2 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h2><ul>
<li>JDK1.8</li>
<li>Centos7</li>
</ul>
<h2 id="主机-两台"><a href="#主机-两台" class="headerlink" title="主机-两台"></a>主机-两台</h2><ul>
<li>centos7_1 :172.16.54.130</li>
<li>centos7_2 :172.16.54.128</li>
</ul>
<h2 id="软件资源"><a href="#软件资源" class="headerlink" title="软件资源"></a>软件资源</h2><ul>
<li>JDK1.8 :<a href="https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html" rel="noopener external nofollow noreferrer" target="_blank">https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html</a></li>
<li>RocketMQ4.5.2 :<a href="http://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/4.5.2/rocketmq-all-4.5.2-bin-release.zip" rel="noopener external nofollow noreferrer" target="_blank">http://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/4.5.2/rocketmq-all-4.5.2-bin-release.zip</a></li>
</ul>
<h2 id="安装JDK"><a href="#安装JDK" class="headerlink" title="安装JDK"></a>安装JDK</h2><p>  首先分别在两台主机上安装JDK1.8，具体安装方法这里就不说了，网上随便搜一搜都有；</p>
<h2 id="配置RocketMQ"><a href="#配置RocketMQ" class="headerlink" title="配置RocketMQ"></a>配置RocketMQ</h2><p>  把下载的RocketMQ包分别上传到两台服务器上，然后用命令解压:</p>
  <figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> unzip rocketmq-all-4.5.2-bin-release.zip</span></span><br></pre></td></tr></table></figure>

<h3 id="编写配置文件"><a href="#编写配置文件" class="headerlink" title="编写配置文件"></a>编写配置文件</h3><p>  这一步很重要，集群的搭建关键在于配置文件的编写，首先看看RocketMq配置文件的解析:</p>
<figure class="highlight properties"><table><tr><td class="code"><pre><span class="line"><span class="comment">#所属集群名字 </span></span><br><span class="line"><span class="attr">brokerClusterName</span>=<span class="string">rocketmq-cluster</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#broker名字，每队master和slave保持一致</span></span><br><span class="line"><span class="attr">brokerName</span>=<span class="string">broker-a</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#0 表示 Master，&gt;0 表示 Slave</span></span><br><span class="line"><span class="attr">brokerId</span>=<span class="string">0 </span></span><br><span class="line"></span><br><span class="line"><span class="comment">#指定主机ip</span></span><br><span class="line"><span class="attr">brokerIP1</span> = <span class="string">主机IP</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#nameServer地址，分号分割</span></span><br><span class="line"><span class="attr">namesrvAddr</span>=<span class="string">主机IP:9876;主机IP:9876</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#在发送消息时，自动创建服务器不存在的topic，默认创建的队列数 </span></span><br><span class="line"><span class="attr">defaultTopicQueueNums</span>=<span class="string">4</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#是否允许 Broker 自动创建Topic，建议线下开启，线上关闭 </span></span><br><span class="line"><span class="attr">autoCreateTopicEnable</span>=<span class="string">true</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#是否允许 Broker 自动创建订阅组，建议线下开启，线上关闭 </span></span><br><span class="line"><span class="attr">autoCreateSubscriptionGroup</span>=<span class="string">true</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#Broker 对外服务的监听端口 </span></span><br><span class="line"><span class="attr">listenPort</span>=<span class="string">10911</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#删除文件时间点，默认凌晨 4点</span></span><br><span class="line"> <span class="attr">deleteWhen</span>=<span class="string">04</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#文件保留时间，默认 48 小时 </span></span><br><span class="line"><span class="attr">fileReservedTime</span>=<span class="string">120</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#commitLog每个文件的大小默认1G </span></span><br><span class="line"><span class="attr">mapedFileSizeCommitLog</span>=<span class="string">1073741824</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#ConsumeQueue每个文件默认存30W条，根据业务情况调整</span></span><br><span class="line"><span class="attr">mapedFileSizeConsumeQueue</span>=<span class="string">300000</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#检测物理文件磁盘空间</span></span><br><span class="line"><span class="attr">diskMaxUsedSpaceRatio</span>=<span class="string">88</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#存储路径</span></span><br><span class="line"><span class="attr">storePathRootDir</span>=<span class="string">/usr/local/rocketmq/store</span></span><br><span class="line"><span class="comment">#commitLog 存储路径 </span></span><br><span class="line"><span class="attr">storePathCommitLog</span>=<span class="string">/usr/local/rocketmq/store/commitlog</span></span><br><span class="line"><span class="comment">#消费队列存储路径存储路径</span></span><br><span class="line"><span class="attr">storePathConsumeQueue</span>=<span class="string">/usr/local/rocketmq/store/consumequeue</span></span><br><span class="line"><span class="comment">#消息索引存储路径</span></span><br><span class="line"><span class="attr">storePathIndex</span>=<span class="string">/usr/local/rocketmq/store/index</span></span><br><span class="line"><span class="comment">#checkpoint 文件存储路径</span></span><br><span class="line"><span class="attr">storeCheckpoint</span>=<span class="string">/usr/local/rocketmq/store/checkpoint</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#Broker 的角色</span></span><br><span class="line"><span class="comment">#- ASYNC_MASTER 异步复制Master</span></span><br><span class="line"><span class="comment">#- SYNC_MASTER 同步双写Master</span></span><br><span class="line"><span class="comment">#- SLAVE </span></span><br><span class="line"><span class="attr">brokerRole</span>=<span class="string">ASYNC_MASTER</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#刷盘方式</span></span><br><span class="line"><span class="comment">#- ASYNC_FLUSH 异步刷盘</span></span><br><span class="line"><span class="comment">#- SYNC_FLUSH 同步刷盘 flushDiskType=ASYNC_FLUSH</span></span><br><span class="line"><span class="comment">#checkTransactionMessageEnable=false</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#abort 文件存储路径</span></span><br><span class="line"><span class="attr">abortFile</span>=<span class="string">/usr/javawork/apache-rocketmq/store/abort</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#限制的消息大小 maxMessageSize=65536</span></span><br></pre></td></tr></table></figure>

<p>以上配置可根据个人需求加入到自己的配置文件中；RocketMQ官方已经为我们创建好了简单的集群配置文件，进去解压后的文件夹，在进入到conf文件夹，可以看到里面有三个文件夹：</p>
<ul>
<li>2m-2s-async :2个master，2个slave，async异步复制</li>
<li>2m-2s-sync :2个master，2个slave，sync同步双写</li>
<li>2m-noslave :2个master,没有slave</li>
</ul>
<p>这里我们用async异步复制模式，进入文件夹，分别编辑：</p>
<h4 id="centos7-1主机编辑如下两个配置文件"><a href="#centos7-1主机编辑如下两个配置文件" class="headerlink" title="centos7_1主机编辑如下两个配置文件"></a>centos7_1主机编辑如下两个配置文件</h4><blockquote>
<p>注意，master和slave的文件存储路径不能用同一个路径，所以必须要区分开。</p>
</blockquote>
<h5 id="broker-a-properties"><a href="#broker-a-properties" class="headerlink" title="broker-a.properties"></a>broker-a.properties</h5><figure class="highlight properties"><table><tr><td class="code"><pre><span class="line"><span class="attr">brokerClusterName</span>=<span class="string">DefaultCluster</span></span><br><span class="line"><span class="attr">brokerName</span>=<span class="string">broker-a</span></span><br><span class="line"><span class="attr">brokerId</span>=<span class="string">0</span></span><br><span class="line"><span class="attr">deleteWhen</span>=<span class="string">04</span></span><br><span class="line"><span class="attr">fileReservedTime</span>=<span class="string">48</span></span><br><span class="line"><span class="attr">brokerRole</span>=<span class="string">ASYNC_MASTER</span></span><br><span class="line"><span class="attr">flushDiskType</span>=<span class="string">ASYNC_FLUSH</span></span><br><span class="line"><span class="attr">namesrvAddr</span>=<span class="string">172.16.54.128:9876;172.16.54.130:9876</span></span><br><span class="line"><span class="attr">listenPort</span>=<span class="string">10911</span></span><br><span class="line"><span class="comment">#存储路径</span></span><br><span class="line"><span class="attr">storePathRootDir</span>=<span class="string">/usr/local/rocketmq/master/store</span></span><br><span class="line"><span class="comment">#commitLog 存储路径 </span></span><br><span class="line"><span class="attr">storePathCommitLog</span>=<span class="string">/usr/local/rocketmq/master/store/commitlog</span></span><br><span class="line"><span class="comment">#消费队列存储路径存储路径</span></span><br><span class="line"><span class="attr">storePathConsumeQueue</span>=<span class="string">/usr/local/rocketmq/master/store/consumequeue</span></span><br><span class="line"><span class="comment">#消息索引存储路径</span></span><br><span class="line"><span class="attr">storePathIndex</span>=<span class="string">/usr/local/rocketmq/master/store/index</span></span><br><span class="line"><span class="comment">#checkpoint 文件存储路径</span></span><br><span class="line"><span class="attr">storeCheckpoint</span>=<span class="string">/usr/local/rocketmq/master/store/checkpoint</span></span><br></pre></td></tr></table></figure>

<p><em>这个监听端口设置设置成10911后还会自动监听10909,10912这两个端口，所以要配置文件要避免设置到相应的端口。</em></p>
<h5 id="broker-a-s-properties"><a href="#broker-a-s-properties" class="headerlink" title="broker-a-s.properties"></a>broker-a-s.properties</h5><figure class="highlight properties"><table><tr><td class="code"><pre><span class="line"><span class="attr">brokerClusterName</span>=<span class="string">DefaultCluster</span></span><br><span class="line"><span class="attr">brokerName</span>=<span class="string">broker-a</span></span><br><span class="line"><span class="attr">brokerId</span>=<span class="string">1</span></span><br><span class="line"><span class="attr">deleteWhen</span>=<span class="string">04</span></span><br><span class="line"><span class="attr">fileReservedTime</span>=<span class="string">48</span></span><br><span class="line"><span class="attr">brokerRole</span>=<span class="string">SLAVE</span></span><br><span class="line"><span class="attr">flushDiskType</span>=<span class="string">ASYNC_FLUSH</span></span><br><span class="line"><span class="attr">namesrvAddr</span>=<span class="string">172.16.54.128:9876;172.16.54.130:9876</span></span><br><span class="line"><span class="attr">listenPort</span>=<span class="string">20911</span></span><br><span class="line"><span class="comment">#存储路径</span></span><br><span class="line"><span class="attr">storePathRootDir</span>=<span class="string">/usr/local/rocketmq/slave/store</span></span><br><span class="line"><span class="comment">#commitLog 存储路径 </span></span><br><span class="line"><span class="attr">storePathCommitLog</span>=<span class="string">/usr/local/rocketmq/slave/store/commitlog</span></span><br><span class="line"><span class="comment">#消费队列存储路径存储路径</span></span><br><span class="line"><span class="attr">storePathConsumeQueue</span>=<span class="string">/usr/local/rocketmq/slave/store/consumequeue</span></span><br><span class="line"><span class="comment">#消息索引存储路径</span></span><br><span class="line"><span class="attr">storePathIndex</span>=<span class="string">/usr/local/rocketmq/slave/store/index</span></span><br><span class="line"><span class="comment">#checkpoint 文件存储路径</span></span><br><span class="line"><span class="attr">storeCheckpoint</span>=<span class="string">/usr/local/rocketmq/slave/store/checkpoint</span></span><br></pre></td></tr></table></figure>

<p><em>这个监听端口设置设置成20911后还会自动监听20909,20912这两个端口，所以要配置文件要避免设置到相应的端口。</em></p>
<h4 id="centos7-2主机编辑如下两个配置文件"><a href="#centos7-2主机编辑如下两个配置文件" class="headerlink" title="centos7_2主机编辑如下两个配置文件"></a>centos7_2主机编辑如下两个配置文件</h4><h5 id="和centos7-1主机配置一样，这边就不写了，不过brokerName要设置成不同的，我这边设置成broker-b。"><a href="#和centos7-1主机配置一样，这边就不写了，不过brokerName要设置成不同的，我这边设置成broker-b。" class="headerlink" title="和centos7_1主机配置一样，这边就不写了，不过brokerName要设置成不同的，我这边设置成broker-b。"></a>和centos7_1主机配置一样，这边就不写了，不过brokerName要设置成不同的，我这边设置成broker-b。</h5><h2 id="设置RocketMQ运行的JVM内存-非必须"><a href="#设置RocketMQ运行的JVM内存-非必须" class="headerlink" title="设置RocketMQ运行的JVM内存(非必须)"></a>设置RocketMQ运行的JVM内存(非必须)</h2><blockquote>
<p>此项设置非必须，如果你主机内存很大的话可以不设置，RocketMQ默认要8G。</p>
</blockquote>
<p>  进入rocketmq-all-4.5.2-bin-release/bin目录，两台主机分别设置runbroker.sh和runserver.sh这两个文件。</p>
<ul>
<li>runbroker.sh：找到如下一行配置</li>
</ul>
<figure class="highlight properties"><table><tr><td class="code"><pre><span class="line"><span class="attr">JAVA_OPT</span>=<span class="string">"$&#123;JAVA_OPT&#125; -server -Xms8g -Xmx8g -Xmn4g"</span></span><br><span class="line"></span><br><span class="line"><span class="attr">改成：</span></span><br><span class="line"><span class="attr">JAVA_OPT</span>=<span class="string">"$&#123;JAVA_OPT&#125; -server -Xms512m -Xmx512m -Xmn256m"</span></span><br></pre></td></tr></table></figure>

<ul>
<li>runserver.sh: 找到如下一行配置</li>
</ul>
<figure class="highlight properties"><table><tr><td class="code"><pre><span class="line"><span class="attr">JAVA_OPT</span>=<span class="string">"$&#123;JAVA_OPT&#125; -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"</span></span><br><span class="line"></span><br><span class="line"><span class="attr">改成：</span></span><br><span class="line"><span class="attr">JAVA_OPT</span>=<span class="string">"$&#123;JAVA_OPT&#125; -server -Xms512m -Xmx512m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"</span></span><br></pre></td></tr></table></figure>

<h2 id="启动RocketMQ"><a href="#启动RocketMQ" class="headerlink" title="启动RocketMQ"></a>启动RocketMQ</h2><blockquote>
<p>启动RocketMQ前为了方便访问，先关闭两台主机的防火墙。执行如下命令：</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">&gt;</span><span class="bash"> <span class="comment"># service firewalld stop</span></span></span><br><span class="line"><span class="meta">&gt;</span><span class="bash"></span></span><br></pre></td></tr></table></figure>
</blockquote>
<blockquote>
</blockquote>
<p>  进入rocketmq-all-4.5.2-bin-release/bin这个目录，两台主机分别执行以下命令：</p>
<ul>
<li>启动namesrv</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> nohup sh mqnamesrv &amp;</span></span><br></pre></td></tr></table></figure>

<ul>
<li>启动broker-master</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> nohup sh mqbroker -c ../conf/2m-2s-async/broker-a.properties &amp;</span></span><br></pre></td></tr></table></figure>

<ul>
<li>启动broker-slave</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> nohup sh mqbroker -c ../conf/2m-2s-async/broker<span class="_">-a</span>-s.properties &amp;</span></span><br></pre></td></tr></table></figure>

<p><em>注意两台主机启动broker时后面的-c记得加载你配置好的配置文件路径，别加载错了</em></p>
<h2 id="搭建Console可视化控制台"><a href="#搭建Console可视化控制台" class="headerlink" title="搭建Console可视化控制台"></a>搭建Console可视化控制台</h2><p>  任意一台机器或者本地下载Console源码，地址：<a href="https://github.com/apache/rocketmq-externals，或者有git的话直接用命令拉取：" rel="noopener external nofollow noreferrer" target="_blank">https://github.com/apache/rocketmq-externals，或者有git的话直接用命令拉取：</a></p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> git <span class="built_in">clone</span> https://github.com/apache/rocketmq-externals.git</span></span><br></pre></td></tr></table></figure>

<p>进去目录：</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> <span class="built_in">cd</span> rocketmq-externals-master/rocketmq-console</span></span><br></pre></td></tr></table></figure>

<p>修改配置文件：</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> vim src/main/resources/application.properties</span></span><br></pre></td></tr></table></figure>

<p>添加两个namesvr的主机ip</p>
<figure class="highlight properties"><table><tr><td class="code"><pre><span class="line"><span class="meta">rocketmq.config.namesrvAddr</span>=<span class="string">172.16.54.128:9876;172.16.54.130:9876</span></span><br></pre></td></tr></table></figure>

<p>然后进项目跟目录，运行项目</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> mvn sprint-boot:run</span></span><br></pre></td></tr></table></figure>

<p>浏览器访问：</p>
<p><img src="http://cdn.mjava.top/blog/rocketmq_console.png" alt="可视化Console界面"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://mjava.top/vue/vue-cli3-11-problem/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="灰灰">
      <meta itemprop="description" content="浅水是喧哗的，深水是沉默的">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="灰色World">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/vue/vue-cli3-11-problem/" class="post-title-link" itemprop="url">Vue Cli3-11创建项目慢的问题</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-09-05 16:33:23" itemprop="dateCreated datePublished" datetime="2019-09-05T16:33:23+00:00">2019-09-05</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-01-27 10:07:24" itemprop="dateModified" datetime="2021-01-27T10:07:24+00:00">2021-01-27</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Vue/" itemprop="url" rel="index"><span itemprop="name">Vue</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>  这几天刚学习vue，于是下载了最新的vue cli3.11来搭建项目，可是搭建的时候一直卡在下载插件见面，就是下面这张图。</p>
<p><img src="/images/vuecreate.png" alt="vuecreate"></p>
<p>网上查了说不能用国内的镜像，WTF，不是说国内的更快吗？好吧，我换！！！</p>
<h2 id="下载nrm"><a href="#下载nrm" class="headerlink" title="下载nrm"></a>下载nrm</h2><p>  看清楚哦，是nrm部署npm！！！nrm 是一个 <code>npm</code> 源管理器，允许你快速地在 <code>npm</code> 源间切换。执行以下命令安装。</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo npm install -g nrm</span><br></pre></td></tr></table></figure>

<h3 id="测试nrm是否安装成功"><a href="#测试nrm是否安装成功" class="headerlink" title="测试nrm是否安装成功"></a>测试nrm是否安装成功</h3><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">nrm -V</span><br></pre></td></tr></table></figure>

<p>如果输出版本号，则说明安装成功。</p>
<h2 id="切换npm源"><a href="#切换npm源" class="headerlink" title="切换npm源"></a>切换npm源</h2>  <figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">nrm ls</span><br></pre></td></tr></table></figure>

<p>此命令会列出npm的所有源</p>
<p><img src="/images/nrmls.png" alt="nrmls"></p>
<p>可以看到我现在使用的是淘宝的源，现在把他切换到npm的源。</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">nrm use npm</span><br></pre></td></tr></table></figure>

<p><img src="/images/nrmuse.png" alt="nrmuse"></p>
<h2 id="再次创建vue项目"><a href="#再次创建vue项目" class="headerlink" title="再次创建vue项目"></a>再次创建vue项目</h2><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">vue create rrr2</span><br></pre></td></tr></table></figure>

<p><img src="/images/vuecreate2.png" alt="vuecreate2"><br><img src="/images/vuecreate3.png" alt="vuecreate3"></p>
<p>项目成功创建！！！</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://mjava.top/docker/docker-mysql/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="灰灰">
      <meta itemprop="description" content="浅水是喧哗的，深水是沉默的">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="灰色World">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/docker/docker-mysql/" class="post-title-link" itemprop="url">Docker下安装mysql并设置用户权限</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-09-03 15:58:46" itemprop="dateCreated datePublished" datetime="2019-09-03T15:58:46+00:00">2019-09-03</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-01-27 10:07:24" itemprop="dateModified" datetime="2021-01-27T10:07:24+00:00">2021-01-27</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Docker/" itemprop="url" rel="index"><span itemprop="name">Docker</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h2><ul>
<li><p>Ubuntu18.04</p>
</li>
<li><p>Docker19.03.1</p>
</li>
<li><p>Mysql5.7</p>
</li>
</ul>
<h2 id="Docker"><a href="#Docker" class="headerlink" title="Docker"></a>Docker</h2><h3 id="拉取镜像"><a href="#拉取镜像" class="headerlink" title="拉取镜像"></a>拉取镜像</h3><p>  Docker拉取镜像默认是从DockerHub上面拉取，上面有各厂商提供的优质官方镜像，可以直接拉取使用。或者也可以用DockerFile自定义构建你自己的镜像。</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo docker pull mysql:5.7			//拉取镜像到本地</span><br></pre></td></tr></table></figure>

<p>注：上面mysql:5.7指的是拉取5.7版本的mysql，如果不加直接写mysql的话默认是拉取mysql的最新版本。</p>
<p><img src="http://cdn.mjava.top/blog/dockerpullmysql.png" alt="拉取镜像"></p>
<p>如果显示上面这样，说明已经拉取好了。</p>
<h3 id="查看镜像"><a href="#查看镜像" class="headerlink" title="查看镜像"></a>查看镜像</h3><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo docker images		//查看本地镜像</span><br></pre></td></tr></table></figure>

<p><img src="http://cdn.mjava.top/blog/dockerimages.png" alt="查看本地镜像"></p>
<h3 id="创建容器"><a href="#创建容器" class="headerlink" title="创建容器"></a>创建容器</h3><h4 id="创建"><a href="#创建" class="headerlink" title="创建"></a>创建</h4><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo docker run -d -p 3306:3306 --name mysql5.7 -e MYSQL_ROOT_PASSWORD=root mysql:5.7</span><br></pre></td></tr></table></figure>

<ul>
<li>-d       指定容器运行于后台</li>
<li>-p       端口映射   主机端口:容器端口</li>
<li>–name    自定义容器名字，方便记忆，不设置的话会随机生产</li>
<li>-e        容器环境变量</li>
</ul>
<p><img src="http://cdn.mjava.top/blog/dockerrun.png" alt="创建容器"></p>
<p>创建好的话会显示一串随机生产的id</p>
<h4 id="查看创建好的容器"><a href="#查看创建好的容器" class="headerlink" title="查看创建好的容器"></a>查看创建好的容器</h4><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo docker ps -a</span><br></pre></td></tr></table></figure>

<ul>
<li>-a        显示所有创建好的容器，如果不加只显示正在运行的容器</li>
</ul>
<p><img src="http://cdn.mjava.top/blog/dockerps.png" alt="查看容器"></p>
<h2 id="Mysql"><a href="#Mysql" class="headerlink" title="Mysql"></a>Mysql</h2><h3 id="进入容器"><a href="#进入容器" class="headerlink" title="进入容器"></a>进入容器</h3><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo docker exec -it mysql5.7 bash</span><br></pre></td></tr></table></figure>

<ul>
<li>-i        打开STDIN，用于控制台交互</li>
<li>-t        分配tty设备，该可以支持终端登录</li>
</ul>
<p><img src="http://cdn.mjava.top/blog/dockerexec.png" alt="进入容器"></p>
<h3 id="登录mysql"><a href="#登录mysql" class="headerlink" title="登录mysql"></a>登录mysql</h3><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">mysql -uroot -p</span><br></pre></td></tr></table></figure>

<p>注：然后输入刚才创建容器时的密码，就是MYSQL_ROOT_PASSWORD这个参数</p>
<h3 id="创建测试数据库"><a href="#创建测试数据库" class="headerlink" title="创建测试数据库"></a>创建测试数据库</h3><figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">database</span> <span class="keyword">test</span>;</span><br></pre></td></tr></table></figure>

<h3 id="创建mysql用户"><a href="#创建mysql用户" class="headerlink" title="创建mysql用户"></a>创建mysql用户</h3><figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">user</span> <span class="string">'zmh'</span>@<span class="string">'%'</span> <span class="keyword">identified</span> <span class="keyword">by</span> <span class="string">'zmh'</span>;</span><br></pre></td></tr></table></figure>

<p>注：”%”表示可以任意ip访问</p>
<h3 id="切换mysql用户"><a href="#切换mysql用户" class="headerlink" title="切换mysql用户"></a>切换mysql用户</h3><figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">alter</span> <span class="keyword">user</span> <span class="string">'zmh'</span> <span class="keyword">identified</span> <span class="keyword">by</span> <span class="string">'zmh'</span>;</span><br></pre></td></tr></table></figure>

<h3 id="授权"><a href="#授权" class="headerlink" title="授权"></a>授权</h3><p>授权test库的所有表的所有权限给zmh用户</p>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">grant</span> <span class="keyword">all</span> <span class="keyword">privileges</span> <span class="keyword">on</span> test.* <span class="keyword">to</span> <span class="string">'zmh'</span>@<span class="string">'%'</span>;</span><br></pre></td></tr></table></figure>

<h3 id="刷新权限"><a href="#刷新权限" class="headerlink" title="刷新权限"></a>刷新权限</h3><figure class="highlight sql"><table><tr><td class="code"><pre><span class="line"><span class="keyword">flush</span> <span class="keyword">privileges</span>;</span><br></pre></td></tr></table></figure>

<p>退出mysql命令行</p>
<figure class="highlight sql"><table><tr><td class="code"><pre><span class="line">exit</span><br></pre></td></tr></table></figure>

<h3 id="客户端连接测试"><a href="#客户端连接测试" class="headerlink" title="客户端连接测试"></a>客户端连接测试</h3><p><img src="http://cdn.mjava.top/blog/sqlclient.png" alt="进入容器"></p>
<p>成功！</p>
<h2 id="附加"><a href="#附加" class="headerlink" title="附加"></a>附加</h2><p>如果要重启mysql的话，不用进容器里面，直接重启容器就可以</p>
<ul>
<li>sudo docker start mysql5.7       启动mysql5.7容器</li>
<li>sudo docker stop mysql5.7        停止mysql5.7容器</li>
<li>sudo docker restart mysql5.7   重启mysql5.7容器</li>
</ul>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://mjava.top/linux/build-docker-pi/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="灰灰">
      <meta itemprop="description" content="浅水是喧哗的，深水是沉默的">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="灰色World">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/linux/build-docker-pi/" class="post-title-link" itemprop="url">树莓派安装docker</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-08-30 18:33:03" itemprop="dateCreated datePublished" datetime="2019-08-30T18:33:03+00:00">2019-08-30</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-01-27 10:07:24" itemprop="dateModified" datetime="2021-01-27T10:07:24+00:00">2021-01-27</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Linux/" itemprop="url" rel="index"><span itemprop="name">Linux</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>  和平常x86_64架构的电脑安装docker不同，树莓派是ARM架构的，所以安装步骤比较繁琐一点。</p>
<h2 id="使用APT源安装docker"><a href="#使用APT源安装docker" class="headerlink" title="使用APT源安装docker"></a>使用APT源安装docker</h2><p>  更新apt软件源及安装必备组件。为了确认所下载软件包的合法性，还需要添加软件源的 GPG 密钥。</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash">sudo apt-get update</span></span><br><span class="line"><span class="meta">$</span><span class="bash">sudo apt-get install \</span></span><br><span class="line">	 apt-transport-https \</span><br><span class="line">     ca-certificates \</span><br><span class="line">     curl \</span><br><span class="line">     gnupg2 \</span><br><span class="line">     lsb-release \</span><br><span class="line">     software-properties-common</span><br><span class="line"><span class="meta">$</span><span class="bash">curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/raspbian/gpg | sudo apt-key add -</span></span><br></pre></td></tr></table></figure>

<h2 id="添加docker-ce-软件源"><a href="#添加docker-ce-软件源" class="headerlink" title="添加docker ce 软件源"></a>添加docker ce 软件源</h2><ul>
<li><p>首先执行以下一行命令，然后记一下输出的结果</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> <span class="built_in">echo</span> $(lsb_release -cs)</span></span><br><span class="line">stretch</span><br></pre></td></tr></table></figure>
</li>
<li><p>在/etc/apt/sources.list.d目录下新建文件docker.list</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> sudo vi /etc/apt/sources.list.d/docker.list</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>在文件里添加下面这行</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">deb [arch=armhf] https://download.docker.com/linux/raspbian $(lsb_release -cs) stable</span><br></pre></td></tr></table></figure>
</li>
<li><p>把$(lsb_release -cs)改为刚才第一行输出的结果，比如我的输出的是stretch，改完后如下</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">deb [arch=armhf] https://download.docker.com/linux/raspbian stretch stable</span><br></pre></td></tr></table></figure>
</li>
<li><p>保存，退出</p>
</li>
</ul>
<h2 id="安装docker-ce"><a href="#安装docker-ce" class="headerlink" title="安装docker ce"></a>安装docker ce</h2><p>  依次执行以下两行命令，即可完成安装</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> sudo apt-get update</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> sudo apt-get install docker-ce</span></span><br></pre></td></tr></table></figure>

<h2 id="启动"><a href="#启动" class="headerlink" title="启动"></a>启动</h2><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> service docker start           启动</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> service docker stop            停止</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> service docker status          状态</span></span><br><span class="line"><span class="meta">$</span><span class="bash"> service docker restart         重启</span></span><br></pre></td></tr></table></figure>
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://mjava.top/linux/problem-jdk-timezone/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="灰灰">
      <meta itemprop="description" content="浅水是喧哗的，深水是沉默的">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="灰色World">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/linux/problem-jdk-timezone/" class="post-title-link" itemprop="url">JDK时区问题</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-08-27 15:26:30" itemprop="dateCreated datePublished" datetime="2019-08-27T15:26:30+00:00">2019-08-27</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-01-27 10:07:24" itemprop="dateModified" datetime="2021-01-27T10:07:24+00:00">2021-01-27</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Linux/" itemprop="url" rel="index"><span itemprop="name">Linux</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>今天碰到一个大坑，弄了快一个小时才解决掉；</p>
<p>一个管理台后端服务，用docker隔离了三个容器，oracle,nginx,tomcat;后发现管理台查出来的时间和现实时间相差8个小时，一查是linux时区问题；</p>
<hr>
<ul>
<li>于是改之,三台容器都输入一下代码</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime</span><br></pre></td></tr></table></figure>

<p>测试了一下，发现问题docker容器的时区是正确了，可是问题并未得到解决，数据库时间还是慢了8个小时。</p>
<hr>
<ul>
<li>于是又查资料，换另外一种设置时区的方法；</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">vi /etc/sysconfig/clock</span><br></pre></td></tr></table></figure>

<p>在里面输入如下内容</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">ZONE="Asia/Shanghai"</span><br><span class="line">UTC=false</span><br><span class="line">ARC=false</span><br></pre></td></tr></table></figure>

<p>保存，重启，测试。。。。。发现还是一样,快疯了</p>
<hr>
<ul>
<li>第三种方法，设置TZ环境变量</li>
</ul>
<blockquote>
<p>设置环境变量可以在设置系统级别的/etc/profile  ,也可以设置用户级别的home目录的.bashrc。由于用的是docker，防止变量重启失效，只能在.bashrc里设置。在.bashrc加入如下内容：</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">export TZ='CST-8'</span><br></pre></td></tr></table></figure>

<p>保存：然后执行</p>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">source .bashrc</span><br></pre></td></tr></table></figure>

<p>使设置立即生效。</p>
<p>重启容器，测试，发现时间正常了。。。。哈哈哈哈</p>
<hr>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>上面问题出在jdk的new Date()方法，所以只要设置jdk所在的那个docker容器的变量就可以，不用每个都设置。jdk的new Date()方法每次调用都会去取环境变量TZ的时区，TZ是TimeZone的缩写，容器内部操作系统并未指定时区（TimeZone）信息，系统默认使用世界标准时（UTC+0),所以导致new Date()出来的数据存库会比当前时间慢8个小时；</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://mjava.top/java/java-equals/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="灰灰">
      <meta itemprop="description" content="浅水是喧哗的，深水是沉默的">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="灰色World">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/java/java-equals/" class="post-title-link" itemprop="url">Java的==和equals</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-08-20 19:22:50" itemprop="dateCreated datePublished" datetime="2019-08-20T19:22:50+00:00">2019-08-20</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-01-27 10:07:24" itemprop="dateModified" datetime="2021-01-27T10:07:24+00:00">2021-01-27</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>在平常工作和学习中，我们一般用==和equals来比较两个对象或数据是否相等。但是什么时候用equals，什么时候用==一直都不怎么清楚，今天整理了下；</p>
<h2 id="首先看看Java的栈空间和堆空间的地址引用"><a href="#首先看看Java的栈空间和堆空间的地址引用" class="headerlink" title="首先看看Java的栈空间和堆空间的地址引用"></a>首先看看Java的栈空间和堆空间的地址引用</h2><p><img src="http://cdn.mjava.top/blog/javaand1.png" alt="Java栈空间和堆空间"></p>
<h2 id="的说明"><a href="#的说明" class="headerlink" title="==的说明"></a>==的说明</h2><p>  在Java中，==对比的是两个对象在空间里的地址是否一致,比如上图的s2==s3返回的是false，s5==s6返回的是为true。话不多说，上代码。</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">demo2</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        String s1=<span class="keyword">new</span> String(<span class="string">"t1"</span>);</span><br><span class="line">        String s2=<span class="keyword">new</span> String(<span class="string">"t2"</span>);</span><br><span class="line">        String s3=<span class="keyword">new</span> String(<span class="string">"t2"</span>);</span><br><span class="line"></span><br><span class="line">        String s4=<span class="keyword">new</span> String(<span class="string">"t3"</span>);</span><br><span class="line">        String s5=<span class="string">"t3"</span>;</span><br><span class="line">        String s6=<span class="string">"t3"</span>;</span><br><span class="line"></span><br><span class="line">        System.out.println(<span class="string">"s2==s3:"</span>+(s2==s3));</span><br><span class="line">        System.out.println(<span class="string">"s5==s6:"</span>+(s5==s6));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>结果：<br><img src="http://cdn.mjava.top/blog/javaand2.png" alt="控制台输出"></p>
<blockquote>
<p>这是因为==比的是在空间里的地址，s2和s3在堆里面是两个不同的对象，所以地址也不同，自然返回就是false。s5和s6是Java的基础数据类型，指向的是常量池里同一个引用，所以地址也相同，返回的就是true。</p>
</blockquote>
<h2 id="equals的说明"><a href="#equals的说明" class="headerlink" title="equals的说明"></a>equals的说明</h2><p>  每个Object里的equals都不一样，我们看看String里的源码</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">equals</span><span class="params">(Object anObject)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (<span class="keyword">this</span> == anObject) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (anObject <span class="keyword">instanceof</span> String) &#123;</span><br><span class="line">        String anotherString = (String)anObject;</span><br><span class="line">        <span class="keyword">int</span> n = value.length;</span><br><span class="line">        <span class="keyword">if</span> (n == anotherString.value.length) &#123;</span><br><span class="line">            <span class="keyword">char</span> v1[] = value;</span><br><span class="line">            <span class="keyword">char</span> v2[] = anotherString.value;</span><br><span class="line">            <span class="keyword">int</span> i = <span class="number">0</span>;</span><br><span class="line">            <span class="keyword">while</span> (n-- != <span class="number">0</span>) &#123;</span><br><span class="line">                <span class="keyword">if</span> (v1[i] != v2[i])</span><br><span class="line">                    <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">                i++;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>首先它会对比地址，如果地址相等，就直接返回true</li>
<li>如果地址不相等，就会对比里面的每一个字符，直到完全相等，然后返回true</li>
</ul>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>　　所以一般如果是对比两个对象是否相等的话，用==就可以。但是如果你要对比两个值是否相等的话，就要用equals了，因为如果用==就会出现上面明明值相等,返回却是false的情况。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://mjava.top/java/java-isnull-four/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="灰灰">
      <meta itemprop="description" content="浅水是喧哗的，深水是沉默的">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="灰色World">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/java/java-isnull-four/" class="post-title-link" itemprop="url">Java中String判断为空的4大方法比较</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-08-20 18:59:15" itemprop="dateCreated datePublished" datetime="2019-08-20T18:59:15+00:00">2019-08-20</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-01-27 10:07:24" itemprop="dateModified" datetime="2021-01-27T10:07:24+00:00">2021-01-27</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="一-四大方法"><a href="#一-四大方法" class="headerlink" title="一.四大方法"></a>一.四大方法</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">demo1</span> </span>&#123;</span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">       String a=<span class="string">""</span>;</span><br><span class="line">       String a2=<span class="keyword">new</span> String();</span><br><span class="line"></span><br><span class="line">       System.out.println(a==<span class="string">""</span>);</span><br><span class="line">       System.out.println(a2==<span class="string">""</span>);</span><br><span class="line">       System.out.println(<span class="string">"------------------------------"</span>);</span><br><span class="line">       System.out.println(a==<span class="keyword">null</span>);</span><br><span class="line">       System.out.println(a2==<span class="keyword">null</span>);</span><br><span class="line">       System.out.println(<span class="string">"------------------------------"</span>);</span><br><span class="line">       System.out.println(a.length()&lt;=<span class="number">0</span>);</span><br><span class="line">       System.out.println(a2.length()&lt;=<span class="number">0</span>);</span><br><span class="line">       System.out.println(<span class="string">"------------------------------"</span>);</span><br><span class="line">       System.out.println(a.isEmpty());</span><br><span class="line">       System.out.println(a2.isEmpty());</span><br><span class="line">       System.out.println(<span class="string">"------------------------------"</span>);</span><br><span class="line">       </span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="二-输出结果"><a href="#二-输出结果" class="headerlink" title="二.输出结果"></a>二.输出结果</h2><p><img src="http://cdn.mjava.top/blog/javaands1.png" alt="控制台输出"></p>
<blockquote>
<p>可以看到用”==”判断的那组出现了不一致的情况</p>
</blockquote>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://mjava.top/algorithm/algorithm-recursive-01/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="灰灰">
      <meta itemprop="description" content="浅水是喧哗的，深水是沉默的">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="灰色World">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/algorithm/algorithm-recursive-01/" class="post-title-link" itemprop="url">递归算法-获取json中指定key的所有值</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-08-17 12:38:52" itemprop="dateCreated datePublished" datetime="2019-08-17T12:38:52+00:00">2019-08-17</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-01-27 10:07:24" itemprop="dateModified" datetime="2021-01-27T10:07:24+00:00">2021-01-27</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Algorithm/" itemprop="url" rel="index"><span itemprop="name">Algorithm</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>今天在工作中遇到要解析json并获取json里所有指定key的值，再把key的值插入对应的数据映射表。于是写了一个递归算法来取值。</p>
<h2 id="1-首先导入alibaba的fastjson，用来解析json。当然也可以用其他的解析包"><a href="#1-首先导入alibaba的fastjson，用来解析json。当然也可以用其他的解析包" class="headerlink" title="1.首先导入alibaba的fastjson，用来解析json。当然也可以用其他的解析包"></a>1.首先导入alibaba的fastjson，用来解析json。当然也可以用其他的解析包</h2><figure class="highlight"><table><tr><td class="code"><pre><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;com.alibaba&lt;/groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;fastjson&lt;/artifactId&gt;</span><br><span class="line">    &lt;version&gt;1.2.58&lt;/version&gt;</span><br><span class="line">&lt;/dependency&gt;</span><br></pre></td></tr></table></figure>

<h2 id="2-创建两个工具类方法，用来判断传入的是不是json对象或json数组"><a href="#2-创建两个工具类方法，用来判断传入的是不是json对象或json数组" class="headerlink" title="2.创建两个工具类方法，用来判断传入的是不是json对象或json数组"></a>2.创建两个工具类方法，用来判断传入的是不是json对象或json数组</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">boolean</span> <span class="title">isJSONObj</span><span class="params">(Object json)</span></span>&#123;</span><br><span class="line">   <span class="keyword">return</span> json <span class="keyword">instanceof</span> JSONObject;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">boolean</span> <span class="title">isJSONArray</span><span class="params">(Object json)</span></span>&#123;</span><br><span class="line">   <span class="keyword">return</span> json <span class="keyword">instanceof</span> JSONArray;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>java中的instanceof也称为类型比较运算符，因为它将实例与类型进行比较。它返回true或false。</p>
</blockquote>
<h2 id="3-建立核心重载方法"><a href="#3-建立核心重载方法" class="headerlink" title="3.建立核心重载方法"></a>3.建立核心重载方法</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">getJSONValue</span><span class="params">(JSONObject json,String k,List&lt;String&gt; list)</span></span>&#123;</span><br><span class="line">    <span class="keyword">for</span> (Object j:json.keySet())&#123;</span><br><span class="line">        <span class="keyword">if</span>(isJSONObj(json.get(j)))&#123;</span><br><span class="line">            <span class="comment">//是对象</span></span><br><span class="line">            JSONObject j2= JSON.parseObject(json.get(j).toString());</span><br><span class="line">            getJSONValue(j2,k,list);</span><br><span class="line">        &#125;<span class="keyword">else</span> <span class="keyword">if</span>(isJSONArray(json.get(j)))&#123;</span><br><span class="line">            JSONArray j3=JSON.parseArray(json.get(j).toString());</span><br><span class="line">            <span class="comment">//是数组</span></span><br><span class="line">            getJSONValue(j3,k,list);</span><br><span class="line">        &#125;<span class="keyword">else</span> <span class="keyword">if</span>(j==k)&#123;</span><br><span class="line">            <span class="comment">//是字符串</span></span><br><span class="line">            list.add(json.get(j).toString());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">getJSONValue</span><span class="params">(JSONArray json,String k,List&lt;String&gt; list)</span></span>&#123;</span><br><span class="line">    <span class="keyword">for</span> (Object j:json)&#123;</span><br><span class="line">        <span class="keyword">if</span>(isJSONObj(j))&#123;</span><br><span class="line">            <span class="comment">//是对象</span></span><br><span class="line">            JSONObject j2= JSON.parseObject(j.toString());</span><br><span class="line">            getJSONValue(j2,k,list);</span><br><span class="line">        &#125;<span class="keyword">else</span> <span class="keyword">if</span>(isJSONArray(j))&#123;</span><br><span class="line">            <span class="comment">//是数组</span></span><br><span class="line">            JSONArray j3=JSON.parseArray(j.toString());</span><br><span class="line">            getJSONValue(j3,k,list);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="4-接下来写一个比较复杂的json，里面有对象嵌套数组的，数组嵌套对象的，数组嵌套数组的"><a href="#4-接下来写一个比较复杂的json，里面有对象嵌套数组的，数组嵌套对象的，数组嵌套数组的" class="headerlink" title="4.接下来写一个比较复杂的json，里面有对象嵌套数组的，数组嵌套对象的，数组嵌套数组的"></a>4.接下来写一个比较复杂的json，里面有对象嵌套数组的，数组嵌套对象的，数组嵌套数组的</h2><p><a href="http://cdn.mjava.top/blog/demojson.txt" rel="noopener external nofollow noreferrer" target="_blank">示例json</a></p>
<h2 id="5-调用方法"><a href="#5-调用方法" class="headerlink" title="5.调用方法"></a>5.调用方法</h2><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">try</span> &#123;</span><br><span class="line">    File file=<span class="keyword">new</span> File(demo1.class.getResource(<span class="string">"/2.json"</span>).getPath());</span><br><span class="line">    FileInputStream fileInputStream=<span class="keyword">new</span> FileInputStream(file);</span><br><span class="line">    InputStreamReader inputStreamReader=<span class="keyword">new</span> InputStreamReader(fileInputStream);</span><br><span class="line">    BufferedReader bufferedReader=<span class="keyword">new</span> BufferedReader(inputStreamReader);</span><br><span class="line">    String line=<span class="string">""</span>;</span><br><span class="line">    StringBuffer json=<span class="keyword">new</span> StringBuffer();</span><br><span class="line">    <span class="keyword">while</span> ((line=bufferedReader.readLine())!=<span class="keyword">null</span>)&#123;</span><br><span class="line">        json.append(line);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    JSONObject j3=JSON.parseObject(json.toString());</span><br><span class="line">    List&lt;String&gt; mid=<span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">    getJSONValue(j3,<span class="string">"interfaceId"</span>,mid);</span><br><span class="line">    System.out.println(mid.toString());</span><br><span class="line">&#125;<span class="keyword">catch</span> (Exception e)&#123;</span><br><span class="line">    System.out.println(e.getMessage());</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="6-成功获取"><a href="#6-成功获取" class="headerlink" title="6.成功获取"></a>6.成功获取</h2><p><img src="http://cdn.mjava.top/blog/json2.png" alt="控制台返回"></p>
<blockquote>
<p>demo源码地址：<a href="https://github.com/z573419235/studyDemo" rel="noopener external nofollow noreferrer" target="_blank">https://github.com/z573419235/studyDemo</a></p>
</blockquote>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://mjava.top/java/problem-java-base64/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="灰灰">
      <meta itemprop="description" content="浅水是喧哗的，深水是沉默的">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="灰色World">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/java/problem-java-base64/" class="post-title-link" itemprop="url">Base64影响泰文字段取值问题</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-08-14 10:39:23" itemprop="dateCreated datePublished" datetime="2019-08-14T10:39:23+00:00">2019-08-14</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-01-27 10:07:24" itemprop="dateModified" datetime="2021-01-27T10:07:24+00:00">2021-01-27</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="今天在工作中，图片要用base64上传，上传数据中还有泰文，然后和前端app联调时发现他们传的泰文这边竟然没存到库里，怀疑是app没有传值过来，于是一番操作"><a href="#今天在工作中，图片要用base64上传，上传数据中还有泰文，然后和前端app联调时发现他们传的泰文这边竟然没存到库里，怀疑是app没有传值过来，于是一番操作" class="headerlink" title="今天在工作中，图片要用base64上传，上传数据中还有泰文，然后和前端app联调时发现他们传的泰文这边竟然没存到库里，怀疑是app没有传值过来，于是一番操作"></a>今天在工作中，图片要用base64上传，上传数据中还有泰文，然后和前端app联调时发现他们传的泰文这边竟然没存到库里，怀疑是app没有传值过来，于是一番操作</h2><h4 id="查看日志"><a href="#查看日志" class="headerlink" title="查看日志"></a>查看日志</h4><blockquote>
<p>what,日志里面竟然有他们传过来的泰文的值</p>
</blockquote>
<h4 id="对比ios和android的数据"><a href="#对比ios和android的数据" class="headerlink" title="对比ios和android的数据"></a>对比ios和android的数据</h4><blockquote>
<p>发现日志里的数据都是一样的，但是android上传的数据全部传入了mysql数据库，ios的除了泰文，其他的也都传到了库里</p>
</blockquote>
<h4 id="确定问题"><a href="#确定问题" class="headerlink" title="确定问题"></a>确定问题</h4><blockquote>
<p>最后对比发现，android的泰文字段三放在base64字段前面的然后传上来的，ios是放在base64字段后面传上来的，怀疑问题在此处</p>
</blockquote>
<h4 id="修复bug"><a href="#修复bug" class="headerlink" title="修复bug"></a>修复bug</h4><blockquote>
<p>于是叫ios也和android一样，把上传字段的顺序调整了以下，把泰文的字段放在base64字段前面，然后上传。改了之后试了以下，，竟然解决了，2222333333</p>
</blockquote>
<p>总结：暂时不知道具体什么原因，有可能是因为base64数据太长了，影响到泰文的字段存储了。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/5/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/5/">5</a><span class="page-number current">6</span>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">灰灰</p>
  <div class="site-description" itemprop="description">浅水是喧哗的，深水是沉默的</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">59</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">16</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">56</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/greycode9" title="GitHub → https://github.com/greycode9" rel="noopener external nofollow noreferrer" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:zhengminghui99@gmail.com" title="E-Mail → mailto:zhengminghui99@gmail.com" rel="noopener external nofollow noreferrer" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://www.yuque.com/huihui-r7gwx" title="https://www.yuque.com/huihui-r7gwx" rel="noopener external nofollow noreferrer" target="_blank">语雀</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        
  <div class="beian"><a href="https://beian.miit.gov.cn" rel="noopener external nofollow noreferrer" target="_blank">赣ICP备17003482号 </a>
  </div>

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">灰灰</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener external nofollow noreferrer" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org" class="theme-link" rel="noopener external nofollow noreferrer" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script>
<script src="/js/schemes/muse.js"></script>
<script src="/js/next-boot.js"></script>



  




  <script src="/js/local-search.js"></script>












  

  
      

<script>
  if (typeof MathJax === 'undefined') {
    window.MathJax = {
      loader: {
          load: ['[tex]/mhchem'],
        source: {
          '[tex]/amsCd': '[tex]/amscd',
          '[tex]/AMScd': '[tex]/amscd'
        }
      },
      tex: {
        inlineMath: {'[+]': [['$', '$']]},
          packages: {'[+]': ['mhchem']},
        tags: 'ams'
      },
      options: {
        renderActions: {
          findScript: [10, doc => {
            document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
              const display = !!node.type.match(/; *mode=display/);
              const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
              const text = document.createTextNode('');
              node.parentNode.replaceChild(text, node);
              math.start = {node: text, delim: '', n: 0};
              math.end = {node: text, delim: '', n: 0};
              doc.math.push(math);
            });
          }, '', false],
          insertedScript: [200, () => {
            document.querySelectorAll('mjx-container').forEach(node => {
              let target = node.parentNode;
              if (target.nodeName.toLowerCase() === 'li') {
                target.parentNode.classList.add('has-jax');
              }
            });
          }, '', false]
        }
      }
    };
    (function () {
      var script = document.createElement('script');
      script.src = '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
      script.defer = true;
      document.head.appendChild(script);
    })();
  } else {
    MathJax.startup.document.state(0);
    MathJax.texReset();
    MathJax.typeset();
  }
</script><!-- hexo-inject:begin --><!-- hexo-inject:end -->

    

  

</body>
</html>
